package com.glc.gao.gavin.rxjavademo.operator;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.glc.gao.gavin.rxjavademo.R;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public abstract class BaseActivity extends AppCompatActivity {
    private String TAG = "RxDEMO";
    private Toolbar toolbar;
    private TextView tvTitle;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getContextView());
        tvTitle = (TextView) findViewById(R.id.tv_title);
        if (getIntent() != null && getIntent().hasExtra("key_title")) {
            tvTitle.setText(getIntent().getStringExtra("key_title"));
        }
        findViewById(R.id.img_home).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        ((TextView) findViewById(R.id.tv_describe)).setText(getDescribeText());
    }

    public abstract int getDescribeText();

    protected abstract int getContextView();


    @Override
    public void onBackPressed() {
        finish();
    }

    protected void print(String msg) {
        Log.d(TAG, this.getClass().getSimpleName() + "print: " + msg);
    }

    public String getNowTimeStr() {
        DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        return formatter.format(new Date());
    }

}
